package com.ymatou.iapi.userservice.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.ExistsTradingPwdBean;
import com.ymatou.iapi.userservice.parameter.UpdateTradingPwdBean;
import com.ymatou.iapi.userservice.parameter.enums.LoginNameEnum;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.ExistsTradingPwdCall;
import com.ymatou.iapi.userservice.service.UpdateTradingPwdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.DesUtil;
import com.ymttest.utils.TestDataManager;
/**
*验证交易密码是否存在Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ExistsTradingPwd{
	private static ExistsTradingPwdBean existstradingpwdBean;
	private static ExistsTradingPwdCall existstradingpwdCall;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("验证交易密码是否存在Test");
	}

	@Before
	public void caseUp() {
		existstradingpwdBean=new ExistsTradingPwdBean();
		existstradingpwdCall=new ExistsTradingPwdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(existstradingpwdCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExistsTradingPwd_001() {
		Logger.start(true,"LoginId登录验证交易密码是否存在,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);			
			
			//验证交易密码不存在
			existstradingpwdBean.setLoginId(cur.getLoginId());
			existstradingpwdBean.setLoginIdType(LoginNameEnum.LoginId);
			existstradingpwdBean.setAppSource("APP");
			existstradingpwdCall.setData(existstradingpwdBean);
			existstradingpwdCall.callService();		
			
			Logger.comment("验证Userinfo的TradingPassword是否存在");
			JUserWapper ju = new JUserWapper();
			List<Userinfo> lui = ju.selectUserinfoByUid(uid);
			Userinfo ui = lui.get(0);
			String TradingPassword = ui.getTradingPassword();
			String ExistsTradingPwd;
			if(TradingPassword == null){
			    ExistsTradingPwd = "false";
			}else{
				ExistsTradingPwd = "true";
			}
			Logger.verifyEquals(ExistsTradingPwd, existstradingpwdCall.getString("Result"), "验证Result");
			Logger.verifyEquals("true", existstradingpwdCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", existstradingpwdCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExistsTradingPwd_002() {
		Logger.start(true,"LoginId登录验证交易密码是否存在,存在,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			UpdateTradingPwdBean updatetradingpwdBean = new UpdateTradingPwdBean();
			UpdateTradingPwdCall updatetradingpwdCall = new UpdateTradingPwdCall();
			
			//设置交易密码
			updatetradingpwdBean.setUserId(uid);
			updatetradingpwdBean.setOldPassword(null);
			updatetradingpwdBean.setNewPassword("abc123");
			// ModifyTradingPassword 或 ModifyLoginPassword
			updatetradingpwdBean.setPasActionType("ModifyTradingPassword");
			updatetradingpwdBean.setLoginMobile(cur.getMobile());
			// ByUserId 或 ByMobile
			updatetradingpwdBean.setAType("ByUserId");
			updatetradingpwdCall.setData(updatetradingpwdBean);
			updatetradingpwdCall.callService();
						
			//验证交易密码存在
			existstradingpwdBean.setLoginId(cur.getLoginId());
			existstradingpwdBean.setLoginIdType(LoginNameEnum.LoginId);
			existstradingpwdBean.setAppSource("APP");
			existstradingpwdCall.setData(existstradingpwdBean);
			existstradingpwdCall.callService();		
			
			Logger.comment("验证Userinfo的TradingPassword是否存在");
			JUserWapper ju = new JUserWapper();
			List<Userinfo> lui = ju.selectUserinfoByUid(uid);
			Userinfo ui = lui.get(0);
			String TradingPassword = ui.getTradingPassword();
			String ExistsTradingPwd;
			if(TradingPassword == null){
			    ExistsTradingPwd = "false";
			}else{
				ExistsTradingPwd = "true";
			}
			Logger.verifyEquals(ExistsTradingPwd, existstradingpwdCall.getString("Result"), "验证Result");
			Logger.verifyEquals("true", existstradingpwdCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", existstradingpwdCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExistsTradingPwd_003() {
		Logger.start(true,"Mail登录验证交易密码是否存在,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);			
			
			//验证交易密码不存在
			existstradingpwdBean.setLoginId(cur.getMail());
			existstradingpwdBean.setLoginIdType(LoginNameEnum.Mail);
			existstradingpwdBean.setAppSource("APP");
			existstradingpwdCall.setData(existstradingpwdBean);
			existstradingpwdCall.callService();		
			
			Logger.comment("验证Userinfo的TradingPassword是否存在");
			JUserWapper ju = new JUserWapper();
			List<Userinfo> lui = ju.selectUserinfoByUid(uid);
			Userinfo ui = lui.get(0);
			String TradingPassword = ui.getTradingPassword();
			String ExistsTradingPwd;
			if(TradingPassword == null){
			    ExistsTradingPwd = "false";
			}else{
				ExistsTradingPwd = "true";
			}
			Logger.verifyEquals(ExistsTradingPwd, existstradingpwdCall.getString("Result"), "验证Result");
			Logger.verifyEquals("true", existstradingpwdCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", existstradingpwdCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExistsTradingPwd_004() {
		Logger.start(true,"Mail登录验证交易密码是否存在,存在,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			UpdateTradingPwdBean updatetradingpwdBean = new UpdateTradingPwdBean();
			UpdateTradingPwdCall updatetradingpwdCall = new UpdateTradingPwdCall();
			
			//设置交易密码
			updatetradingpwdBean.setUserId(uid);
			updatetradingpwdBean.setOldPassword(null);
			updatetradingpwdBean.setNewPassword("abc123");
			// ModifyTradingPassword 或 ModifyLoginPassword
			updatetradingpwdBean.setPasActionType("ModifyTradingPassword");
			updatetradingpwdBean.setLoginMobile(cur.getMobile());
			// ByUserId 或 ByMobile
			updatetradingpwdBean.setAType("ByUserId");
			updatetradingpwdCall.setData(updatetradingpwdBean);
			updatetradingpwdCall.callService();
						
			//验证交易密码存在
			existstradingpwdBean.setLoginId(cur.getMail());
			existstradingpwdBean.setLoginIdType(LoginNameEnum.Mail);
			existstradingpwdBean.setAppSource("APP");
			existstradingpwdCall.setData(existstradingpwdBean);
			existstradingpwdCall.callService();		
			
			Logger.comment("验证Userinfo的TradingPassword是否存在");
			JUserWapper ju = new JUserWapper();
			List<Userinfo> lui = ju.selectUserinfoByUid(uid);
			Userinfo ui = lui.get(0);
			String TradingPassword = ui.getTradingPassword();
			String ExistsTradingPwd;
			if(TradingPassword == null){
			    ExistsTradingPwd = "false";
			}else{
				ExistsTradingPwd = "true";
			}
			Logger.verifyEquals(ExistsTradingPwd, existstradingpwdCall.getString("Result"), "验证Result");
			Logger.verifyEquals("true", existstradingpwdCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", existstradingpwdCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExistsTradingPwd_005() {
		Logger.start(true,"Mobile登录验证交易密码是否存在,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);			
			
			//验证交易密码不存在
			existstradingpwdBean.setLoginId(cur.getMail());
			existstradingpwdBean.setLoginIdType(LoginNameEnum.Mobile);
			existstradingpwdBean.setAppSource("APP");
			existstradingpwdCall.setData(existstradingpwdBean);
			existstradingpwdCall.callService();		
			
			Logger.comment("验证Userinfo的TradingPassword是否存在");
			JUserWapper ju = new JUserWapper();
			List<Userinfo> lui = ju.selectUserinfoByUid(uid);
			Userinfo ui = lui.get(0);
			String TradingPassword = ui.getTradingPassword();
			String ExistsTradingPwd;
			if(TradingPassword == null){
			    ExistsTradingPwd = "false";
			}else{
				ExistsTradingPwd = "true";
			}
			Logger.verifyEquals(ExistsTradingPwd, existstradingpwdCall.getString("Result"), "验证Result");
			Logger.verifyEquals("true", existstradingpwdCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", existstradingpwdCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExistsTradingPwd_006() {
		Logger.start(true,"Mobile登录验证交易密码是否存在,存在,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			UpdateTradingPwdBean updatetradingpwdBean = new UpdateTradingPwdBean();
			UpdateTradingPwdCall updatetradingpwdCall = new UpdateTradingPwdCall();
			
			//设置交易密码
			updatetradingpwdBean.setUserId(uid);
			updatetradingpwdBean.setOldPassword(null);
			updatetradingpwdBean.setNewPassword("abc123");
			// ModifyTradingPassword 或 ModifyLoginPassword
			updatetradingpwdBean.setPasActionType("ModifyTradingPassword");
			updatetradingpwdBean.setLoginMobile(cur.getMobile());
			// ByUserId 或 ByMobile
			updatetradingpwdBean.setAType("ByUserId");
			updatetradingpwdCall.setData(updatetradingpwdBean);
			updatetradingpwdCall.callService();
						
			//验证交易密码存在
			existstradingpwdBean.setLoginId(cur.getMobile());
			existstradingpwdBean.setLoginIdType(LoginNameEnum.Mobile);
			existstradingpwdBean.setAppSource("APP");
			existstradingpwdCall.setData(existstradingpwdBean);
			existstradingpwdCall.callService();		
			
			Logger.comment("验证Userinfo的TradingPassword是否存在");
			JUserWapper ju = new JUserWapper();
			List<Userinfo> lui = ju.selectUserinfoByUid(uid);
			Userinfo ui = lui.get(0);
			String TradingPassword = ui.getTradingPassword();
			String ExistsTradingPwd;
			if(TradingPassword == null){
			    ExistsTradingPwd = "false";
			}else{
				ExistsTradingPwd = "true";
			}
			Logger.verifyEquals(ExistsTradingPwd, existstradingpwdCall.getString("Result"), "验证Result");
			Logger.verifyEquals("true", existstradingpwdCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", existstradingpwdCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExistsTradingPwd_007() {
		Logger.start(true,"loginid为空验证交易密码是否存在,失败");
		try {				
			
			//验证交易密码不存在
			existstradingpwdBean.setLoginId(null);
			existstradingpwdBean.setLoginIdType(LoginNameEnum.LoginId);
			existstradingpwdBean.setAppSource("APP");
			existstradingpwdCall.setData(existstradingpwdBean);
			existstradingpwdCall.callService();		
			
			Logger.verifyIsContains("loginId:loginId can't empty", existstradingpwdCall.getString("LastErrorMessage"), "验证LastErrorMessage");
			Logger.verifyEquals("false", existstradingpwdCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", existstradingpwdCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExistsTradingPwd_008() {
		Logger.start(true,"LoginId登录验证交易密码是否存在,密码使用加密模式,存在,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			UpdateTradingPwdBean updatetradingpwdBean = new UpdateTradingPwdBean();
			UpdateTradingPwdCall updatetradingpwdCall = new UpdateTradingPwdCall();
			
			//设置交易密码
			updatetradingpwdBean.setUserId(uid);
			updatetradingpwdBean.setOldPassword(null);
			updatetradingpwdBean.setPasswordType(1);
			
			String pwd = DesUtil.encrypt("abc123",DesUtil.DES_KEY_STRING,DesUtil.DES_IVPARAMETER);
			updatetradingpwdBean.setNewPassword(pwd);
			// ModifyTradingPassword 或 ModifyLoginPassword
			updatetradingpwdBean.setPasActionType("ModifyTradingPassword");
			updatetradingpwdBean.setLoginMobile(cur.getMobile());
			// ByUserId 或 ByMobile
			updatetradingpwdBean.setAType("ByUserId");
			updatetradingpwdCall.setData(updatetradingpwdBean);
			updatetradingpwdCall.callService();
						
			//验证交易密码存在
			existstradingpwdBean.setLoginId(cur.getLoginId());
			existstradingpwdBean.setLoginIdType(LoginNameEnum.LoginId);
			existstradingpwdBean.setAppSource("APP");
			existstradingpwdCall.setData(existstradingpwdBean);
			existstradingpwdCall.callService();		
			
			Logger.comment("验证Userinfo的TradingPassword是否存在");
			JUserWapper ju = new JUserWapper();
			List<Userinfo> lui = ju.selectUserinfoByUid(uid);
			Userinfo ui = lui.get(0);
			String TradingPassword = ui.getTradingPassword();
			String ExistsTradingPwd;
			if(TradingPassword == null){
			    ExistsTradingPwd = "false";
			}else{
				ExistsTradingPwd = "true";
			}
			Logger.verifyEquals(ExistsTradingPwd, existstradingpwdCall.getString("Result"), "验证Result");
			Logger.verifyEquals("true", existstradingpwdCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", existstradingpwdCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}